#include "slepdef.h"
#include "slepblas.h"
#include "slep.h"
#include "sleputil.h"
#include <string.h>

void testRunLR1(){
	OPTS opts;
	slep_matrix* A;
	slep_vector *x, *y, *funVal, *LValue;
	double rho;
	stopWatch timer;

	A = slepAllocDenseMatrix(1000,1000);
	x = slepAllocDenseVector(1000);
	y = slepAllocDenseVector(1000);
	funVal = slepAllocDenseVector(1000);
	LValue = slepAllocDenseVector(1000);

	slep_randn(A->data.mtrx,1000*1000,0.,1.);
	slep_randn(x->data.vctr,1000,0.,1.); // its xOrin here..
	slep_randn(y->data.vctr,1000,0.,1.);
	slep_daAxpby(SlepNoTranspose,1.,A,x,0.01,y);

	rho=0.2;

	opts.lFlag=0;
	opts.mFlag=0;

	opts.rsL2=0.0;
	opts.maxIter=100;

	startTimer(&timer);
	memset(x->data.vctr,0,sizeof(double)*1000);
	stopTimer(&timer);
	printf("Time taken for setting zeroes = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	slep_dvcopy(x,funVal);
	stopTimer(&timer);
	printf("Time taken for copying = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	slep_daxpy(1.,x,funVal);
	stopTimer(&timer);
	printf("Time taken for daxpy = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	slep_ddot(x,funVal);
	stopTimer(&timer);
	printf("Time taken for ddot = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	slep_dasum(x);
	stopTimer(&timer);
	printf("Time taken for dasum = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	slep_dnrm2(x);
	stopTimer(&timer);
	printf("Time taken for dnrm2 = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	LeastRTestImplementation(A,y,rho,&opts,x,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	LeastRTestImplementation(A,y,rho,&opts,x,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));

	startTimer(&timer);
	LeastRTestImplementation(A,y,rho,&opts,x,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));


	slepVerboseWriteDenseVector(SLEPWD "result.vctr",x);
	slepVerboseWriteDenseVector(SLEPWD "funVal.vctr",funVal);
	slepVerboseWriteDenseVector(SLEPWD "LValue.vctr",LValue);
}